/**
 * Por Crysfel Villa
 * @class Extmx.grid.CheckColumn
 * Clase que permite desplegar un checkbox en una celda de manera dinámica
 *        
 * @extends Ext.grid.Column
 * @autor Ing. Crysfel Villa<br>
 *        crysfel@bleext.com<br>
 *        http://www.crysfel.com
 * @fecha 06 de febrero 2011. Monterrey NL
 * 
 */

Ext.ns('Bleext.ux.grid');

Extmx.grid.CheckColumn = Ext.extend(Ext.grid.Column, {
	validation	: Ext.emptyFn,
	
	constructor	: function(){
		Extmx.grid.CheckColumn.superclass.constructor.apply(this,arguments);
		
		if(this.grid && !this.grid.clickevent){
			this.grid.on("cellclick",this.onCellClick,this);
			this.grid.clickevent = true;
			this.cm = this.grid.getColumnModel();
		}
	},
	
	onCellClick	: function(grid, rowIndex, columnIndex, event ){
		if(this.validation(rowIndex,columnIndex)){
			var id = this.cm.getColumnId(columnIndex);
			var column = this.cm.getColumnById(id);

			if(column && column.xtype === "checkcolumn"){
				var record = grid.store.getAt(rowIndex),
					dataIndex = this.cm.getDataIndex(columnIndex);

				record.set(dataIndex, !record.data[dataIndex]);
			}
		}
	},

    renderer : function(v, p, record){
        p.css += ' x-grid3-check-col-td'; 
        return String.format('<div class="x-grid3-check-col{0}">&#160;</div>', v ? '-on' : '');
    }
});

// register ptype. Deprecate. Remove in 4.0
Ext.preg('checkcolumn', Extmx.grid.CheckColumn);

// register Column xtype
Ext.grid.Column.types.checkcolumn = Extmx.grid.CheckColumn;